package com.weiqiao.mall.repository.impl;

import com.weiqiao.base.dao.impl.BaseMongoDaoImpl;
import com.weiqiao.mall.repository.IEquityCardRepository;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 权益卡数据层
 */
@Repository("EquityCardRepositoryImpl")
public class EquityCardRepositoryImpl extends BaseMongoDaoImpl implements IEquityCardRepository {
    private final static String collectionName = "equity_";

    @Override
    public int countNum(int company_id, Bson filter) {
        return this.statististics(collectionName+company_id,filter);
    }

    @Override
    public List<String> findAllEquityCard(int company_id, Bson filter, Bson sort){
        return this.findFilterSort(collectionName+company_id, filter, sort);
    }

    @Override
    public boolean delEquity(int company_id, Bson filter, Document doc) {
        return this.updateOne(collectionName+company_id, filter, doc, false);
    }

    @Override
    public boolean updateState(int company_id,Document doc,Bson filter) {
        return this.updateMany(collectionName+company_id, filter, doc, false);
    }

    @Override
    public boolean add(int company_id,String json) {
        return this.inSert(collectionName+company_id, json);
    }

    @Override
    public boolean updateEquityCard(int company_id,Bson filter,Document doc) {
        return this.updateOne(collectionName+company_id, filter, doc, false);
    }

    @Override
    public String getOneEquityCardByFilter(int company_id,Bson filter){
        return this.findOne(collectionName+company_id,filter);
    }
}
